//
//  MineViewController.m
//  SampleApp2
//
//  Created by GXHC on 2023/6/7.
//

#import "MineViewController.h"

@interface MineViewController ()<UIScrollViewDelegate, UIGestureRecognizerDelegate>

@end

@implementation MineViewController
- (instancetype)init{
	self = [super init];
	if(self){
		self.tabBarItem.title=@"我的";
		self.tabBarItem.image = [UIImage imageNamed:@"home"];
		self.tabBarItem.selectedImage = [UIImage imageNamed:@"home_selected"];
	}
	return self;
}

- (void)viewDidLoad {
	[super viewDidLoad];
	// Do any additional setup after loading the view.
	NSLog(@"MineViewController");
	self.view.backgroundColor = [UIColor whiteColor];
	UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
	scrollView.delegate = self;
	scrollView.backgroundColor = [UIColor grayColor];
	scrollView.contentSize = CGSizeMake(self.view.bounds.size.width*5, self.view.bounds.size.height);
	NSArray *colorArray = @[[UIColor redColor], [UIColor blueColor], [UIColor yellowColor], [UIColor greenColor],[UIColor grayColor]];
	for (int i=0; i<5; i++) {
		[scrollView addSubview:({
			UIView *view = [[UIView alloc] initWithFrame:CGRectMake(scrollView.bounds.size.width*i,0,scrollView.bounds.size.width, scrollView.bounds.size.height)];
			UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewClick)];
			tapGesture.delegate = self;
			[view addGestureRecognizer:tapGesture];
			view.backgroundColor=colorArray[i];
			view;
		})];
	}
	scrollView.pagingEnabled = YES;
	
	[self.view addSubview:scrollView];
	
}

-(void)viewClick{
	NSURL *urlScheme = [NSURL URLWithString:@"TestScheme://"];
	
	if([[UIApplication sharedApplication]canOpenURL:urlScheme]){
		[[UIApplication sharedApplication]openURL:urlScheme options:nil
		completionHandler:^(BOOL success) {
			
		}];
		NSLog(@"can open");
	}else{
		NSLog(@"can not open");
	}
	
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
	NSLog(@"scrollViewDidScroll: - %@", @(scrollView.contentOffset.x));
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
	NSLog(@"scrollViewWillBeginDragging: - %@", @(scrollView.contentOffset.x));
}

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset API_AVAILABLE(ios(5.0)){
	NSLog(@"scrollViewWillEndDragging: - %@", @(scrollView.contentOffset.x));
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
	NSLog(@"scrollViewDidEndDragging: - %@", @(scrollView.contentOffset.x));
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
	NSLog(@"scrollViewWillBeginDecelerating: - %@", @(scrollView.contentOffset.x));
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
	NSLog(@"scrollViewDidEndDecelerating: - %@", @(scrollView.contentOffset.x));
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
